<?php // -*-coding:utf-8; mode:php-mode;-*-
/**
 * @file   UserService.php
 * @author koocyton <koocyton@gmail.com>
 * @date   Mon Dec 14 17:49:51 2009
 * 
 * @brief  用户的 Service
 * @package       UserService
 * 
 */

namespace service;

use entity;

use dao;

use framework\util;

/** 
 * 用户的的Service
 *
 * @package       UserService
 */
class UserService {
	
	/**
	 * @var dao\UserDao $userDao
	 */
	private $userDao;
	
	public function __construct()
	{
		$this->userDao = util\Singleton::get("dao\\UserDao");
	}
	
	public function login($loginName, $loginPass)
	{
		$user = $this->userDao->fetchUserByLoginName($loginName);
		if (empty($user))
		{
			throw new \Exception("此用户不存在");
		}
		elseif ($user->loginPass != entity\User::encryptPassword($loginPass)) {
			throw new \Exception("输入的密码错误");
		}
		
		return $user;
	}
}